package com.woniuxy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.aspect.LogRecord;
import com.woniuxy.dao.CarMaintenanceMapper;
import com.woniuxy.dto.CarMaintenanceDto;
import com.woniuxy.entity.CarMaintenance;
import com.woniuxy.service.CarMaintenanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CarMaintenanceServiceImpl implements CarMaintenanceService {

    @Autowired
    private CarMaintenanceMapper carMaintenanceMapper;
    /**
     * 分页查询
     *
     * @param pageNum          当前页
     * @param pageSize         每页大小
     * @return 分页对象
     */
    @Override
    public PageInfo<CarMaintenanceDto> findByPage(Map<String,Object> condition, int pageNum, int pageSize) {
        //1.设置页码和每页大小
        PageHelper.startPage(pageNum, pageSize);
        //2.调用DAO层查询
        List<CarMaintenanceDto> list = carMaintenanceMapper.findAll(condition);
        //3.返回PageInfo对象
        return new PageInfo<>(list);
    }

    /**
     * 添加
     *
     * @param carMaintenance
     */
    @Override
    public int save(CarMaintenance carMaintenance) {
        return carMaintenanceMapper.save(carMaintenance);
    }

    /**
     * 修改
     *
     * @param carMaintenance
     */
    @LogRecord
    @Override
    public int updateById(CarMaintenance carMaintenance) {
        return carMaintenanceMapper.updateById(carMaintenance);
    }

    /**
     * 删除
     *
     * @param id
     */
    @LogRecord
    @Override
    public int deleteById(Integer id) {
        return carMaintenanceMapper.deleteById(id);
    }

    /**
     * 批量删除
     *
     * @param ids
     */
    @Override
    public int deleteBatch(String[] ids) {
        return carMaintenanceMapper.deleteBatch(ids);
    }

    /**
     * 导出所有数据Excel
     */
    @Override
    public List<CarMaintenanceDto> findAll() {
        return carMaintenanceMapper.findAll(null);
    }

    /**
     * 批量添加数据
     *
     * @param carMaintenanceList
     */
    @Override
    public int insertBatch(List<CarMaintenanceDto> carMaintenanceList) {
        return carMaintenanceMapper.insertBatch(carMaintenanceList);
    }


}
